﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CRM.BLL;
using System.Configuration;

namespace CRM.Web.Common
{
    public class PageBase : System.Web.UI.Page
    {
        private bool _VerificationRight = true;
        private string _pageClassName = string.Empty;
        private string _resourcesPath = string.Empty;



        /// <summary>
        /// Gets or sets the name of the page class.
        /// </summary>
        /// <value>
        /// The name of the page class.
        /// </value>
        public string PageClassName
        {
            get { return _pageClassName; }
            set { _pageClassName = value; }
        }
        public bool VerificationRight
        {
            get { return _VerificationRight; }
            set { _VerificationRight = value; }
        }

        /// <summary>
        /// Gets the resources path.
        /// </summary>
        public string ResourcesPath
        {
            get { return _resourcesPath; }
        }


        /// <summary>
        /// 用户登录信息
        /// </summary>
        protected UserLoginInfo _userLoginInfo;

        public PageBase()
        {
            _pageClassName = this.Page.ToString();
        }

        /// <summary>
        /// 配置
        /// </summary>
        protected T_CONFIG_BLL configBll = new T_CONFIG_BLL();

        protected override void OnInit(EventArgs e)
        {
            this.Page.Title = GetTitle();
            _resourcesPath = WebCommon.GetPageResourcesPath();
            base.OnInit(e);
            if (VerificationRight)
            {
                UserLoginInfo.CheckLoginInfo();
                _userLoginInfo = UserLoginInfo.GetLoginInfo();
            }
        }


        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (VerificationRight)
            {
                UserLoginInfo.CheckMenuRight();
                UserLoginInfo.CheckPermissionRight(PageClassName);
            }
        }

        public string GetTitle()
        {
            string title = string.Empty;
            if (ConfigurationManager.AppSettings["SystemTitle"] != null)
            {
                title = ConfigurationManager.AppSettings["SystemTitle"].ToString();
            }
            return title;
        }





    }
}
